package guijavacommander.tasks;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;

import guijavacommander.actions.CreateDirAction;

/**
 * User: Deady
 * Date: 16.07.2009
 * Time: 11:38:10
 */
public class MoveFilesTask extends AbstractTask {

    private File[] srcFiles;
    private File destFolder;
    private Log logger = LogFactory.getLog(MoveFilesTask.class);

    public MoveFilesTask(File destFolder, File[] srcFiles) {
        this.destFolder = destFolder;
        this.srcFiles = srcFiles;
    }

    public void execute() {
        int i = 0;
        for (File f : srcFiles) {
            if (!f.getParentFile().equals(destFolder)) {
                logger.debug("Moving: "+f.getAbsolutePath()+" to "+destFolder);
                boolean res = f.renameTo(new File(destFolder, f.getName()));
                fireProgressChanged(i);
            }
            i++;
        }
    }

    public int getMin() {
        return 0;
    }

    public int getMax() {
        return srcFiles.length;
    }

    public String getDescription() {
        return "Moving files";
    }
}
